#include <stdio.h>
#define D(s) s=p[e++]-48;while(p[e]!=32&&p[e])s=10*s+p[e++]-48;e++;
void main(int y,char**a)
{
	char*p=*a;
	int n,m,u,d,s=0x7fffffff,e=0,t,c;
	gets(p);
	D(n)D(m)
	while(m--){
		gets(p),e=0;
		D(u)D(d)
		c=n*u/(u+d);
		t=n*u-c*(u+d);
		s=s>t?t:s;
	}
	printf("%d",s);
}